var ws_protocol = 'ws'; // ws 或 wss
var ws_ip = '127.0.0.1';
var ws_port = 9326;

var heartbeatTimeout = 60000; // 心跳超时时间，单位：毫秒
var reconnInterval = 5000; // 重连间隔时间，单位：毫秒

var binaryType = 'blob'; // 'blob' or 'arraybuffer';//arraybuffer是字节
var handler = new PushHandler();
var default_deviceid = "screen_" + new Date().getTime();
var tiows;
var ws_appid = "screen_default";
function initScreenWs(params) {

  if (!params) {
    params = {}
  }
  ws_protocol = params['ws_protocol'] || ws_protocol;
  ws_ip = params['ws_ip'] || ws_ip;
  ws_port = params['ws_port'] || ws_port;

  heartbeatTimeout = params['heartbeatTimeout'] || heartbeatTimeout;
  reconnInterval = params['reconnInterval'] || reconnInterval;

  var deviceid = params['deviceid'] || default_deviceid;
  var deviceip = params['deviceip'] || "";
  ws_appid = params['appid'] || ws_appid;

  // 参数，get方式传递
  var login_token = params['token'] || 'data_visual';
  var login_password = params['password'] || '000000';
  var queryString = "utype=client&appid=" + ws_appid + "&token=" + login_token + "&deviceid=" + deviceid + "&deviceip="+deviceip ;
  var param = queryString;
  tiows = new tio.ws(ws_protocol, ws_ip, ws_port, queryString, param, handler, heartbeatTimeout, reconnInterval, binaryType);

  tiows.connect();
}



function send() {
  var msg = document.getElementById('textId');
  tiows.send(msg.value);
}

function clearMsg() {
  document.getElementById('contentId').innerHTML = '';
}


function send2Server(msg) {
  // msg ，约定的消息格式
  var demo = {
    'msgType': 'event',//deviceinfo,devicestatus
    'data': {
      'eventKey': 'jieping',
      'content': ''
    }
  };
  tiows.send(msg);
}